//
//  HRMessageWhoLookTableViewCell.m
//  SpeedDating
//
//  Created by ISU1 on 17/2/8.
//  Copyright © 2017年 isu. All rights reserved.
//

#import "FriendWhoLookTableViewCell.h"
#import "UIView+SDAutoLayout.h"

@implementation FriendWhoLookTableViewCell
{
    UIImageView *_selectImageView;
    UILabel *_titLabel;
    UILabel *_userNameLabel;
    UILabel *_line;
    UILabel *_titLabelBottom;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setup {
    _selectImageView = [UIImageView new];
    _selectImageView.image = [UIImage imageNamed:@"Friend_news_eyes"];
    _titLabel = [UILabel new];
    _titLabel.font = FontP(16);
    _titLabelBottom = [UILabel new];
    _titLabelBottom.font = FontP(12);
    _titLabelBottom.textColor = ColorI(0x2e353f);
    _userNameLabel = [UILabel new];
    _userNameLabel.numberOfLines = 0;
    _line = [UILabel new];
    _line.backgroundColor = TheLinColor;
    NSArray *views = @[_selectImageView,_titLabel,_userNameLabel,_line,_titLabelBottom];
    [self.contentView sd_addSubviews:views];
    UIView *contentView = self.contentView;
    
    _selectImageView.sd_layout
    .leftSpaceToView(contentView, 15)
    .topSpaceToView(contentView, 15)
    .heightIs(15)
    .widthIs(20);
    
    _titLabel.sd_layout
    .leftSpaceToView(_selectImageView, 15)
    .topSpaceToView(contentView, 10)
    .heightIs(15)
    .rightSpaceToView(contentView, 15);
    
    _titLabelBottom.sd_layout
    .leftSpaceToView(_selectImageView, 15)
    .topSpaceToView(_titLabel, 5)
    .heightIs(15)
    .rightSpaceToView(contentView, 15);

    _userNameLabel.sd_layout
    .leftEqualToView(_titLabel)
    .rightEqualToView(_titLabel)
    .autoHeightRatio(0);
    
    _line.sd_layout
    .leftEqualToView(contentView)
    .rightEqualToView(contentView)
    .topSpaceToView(_titLabelBottom, 5)
    .heightIs(1);
    [self setupAutoHeightWithBottomView:_line bottomMargin:0];
}

- (void)setIsSelect:(BOOL)isSelect {
    if (isSelect) {
        _selectImageView.hidden = NO;
    } else {
        _selectImageView.hidden = YES;
    }
}

- (void)setTitle:(NSString *)title {
    _titLabel.text = title;
}
- (void)setTitleBottom:(NSString *)titleBottom{
    _titLabelBottom.text = titleBottom;
}

- (void)setUserArray:(NSArray *)userArray {
    if (userArray.count) {
        NSMutableArray *array = @[].mutableCopy;
        for (NSDictionary *dic in userArray) {
            NSString *name = dic[@"nickName"];
            [array addObject:name];
        }
        NSString *nameString = [array componentsJoinedByString:@","];
        _userNameLabel.text = nameString;
        _userNameLabel.sd_layout
        .topSpaceToView(_titLabel, 15);
        _userNameLabel.hidden = NO;
    } else {
        _userNameLabel.sd_layout
        .topSpaceToView(_titLabel, 0)
        .heightIs(0);
        _userNameLabel.hidden = YES;
    }
}

@end
